<?php

/**
 * @filename websocket.php 
 * @encoding UTF-8 
 * @author  fwz 
 * @datetime 2018-6-8  11:10:11
  */

//创建一个websocket 
$ws = new swoole_websocket_server("0,0,0,0",9505);

//open 建立链接 $ws,服务器。$request:客户端信息
$ws->on("open",function($ws,$request){
    var_dump($request);
    $ws->push($request->fd,"welcome \n;");
});

//message 接受数据
$ws->on("message",function($ws,$request){
    echo "message:".$request->data;
    $ws->push($request->fd,"it is message");
    
});
//close
$ws->on("close",function($ws,$request){
    echo "close \n";
});

$ws->start();

